#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
VERSION:=@PACKAGE_VERSION@
ARCH:=@ARCHITECTURE@
INTLIB:=INTEGER_LIBRARY

ifeq ($(INTLIB),gmp)
SUBDIR=halvm-gmp
CONFIGURE_FLAGS=--enable-gmp
else
SUBDIR=halvm
CONFIGURE_FLAGS=
endif

%:
	dh $@

override_dh_auto_clean:
	echo "skip dh_auto_clean"

override_dh_auto_configure:
	dh_auto_configure -- $(CONFIGURE_FLAGS)

override_dh_update_autotools_config:
	echo "skip autottolls_config; we like our config.sub, thanks."

override_dh_shlibdeps:
	dh_shlibdeps --dpkg-shlibdeps-params="--ignore-missing-info -l$(shell pwd)/debian/$(SUBDIR)/usr/lib/$(ARCH)-linux-gnu/HaLVM-$(VERSION)/lib"

override_dh_strip:
	dh_strip
	chrpath -d debian/$(SUBDIR)/usr/lib/$(ARCH)-linux-gnu/HaLVM-$(VERSION)/bin/alex
	chrpath -d debian/$(SUBDIR)/usr/lib/$(ARCH)-linux-gnu/HaLVM-$(VERSION)/bin/cabal
	chrpath -d debian/$(SUBDIR)/usr/lib/$(ARCH)-linux-gnu/HaLVM-$(VERSION)/bin/ghc
	chrpath -d debian/$(SUBDIR)/usr/lib/$(ARCH)-linux-gnu/HaLVM-$(VERSION)/bin/ghc-pkg
	chrpath -d debian/$(SUBDIR)/usr/lib/$(ARCH)-linux-gnu/HaLVM-$(VERSION)/bin/happy
	chrpath -d debian/$(SUBDIR)/usr/lib/$(ARCH)-linux-gnu/HaLVM-$(VERSION)/bin/HsColour
	chrpath -r /usr/lib/$(ARCH)-linux-gnu/HaLVM-$(VERSION)/lib \
	             debian/$(SUBDIR)/usr/lib/$(ARCH)-linux-gnu/HaLVM-$(VERSION)/bin/hsc2hs.bin
	chrpath -r /usr/lib/$(ARCH)-linux-gnu/HaLVM-$(VERSION)/lib \
	             debian/$(SUBDIR)/usr/lib/$(ARCH)-linux-gnu/HaLVM-$(VERSION)/bin/haddock
	mv debian/$(SUBDIR)/usr/share/doc/ghc* debian/$(SUBDIR)/usr/share/doc/HaLVM-ghc
	mkdir -p debian/$(SUBDIR)/usr/share/HaLVM-$(VERSION)
	cp -r examples debian/$(SUBDIR)/usr/share/HaLVM-$(VERSION)/
